﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace WpfApp64.Models
{
    public enum Gerder
    {
        F,
        M
    }

    public class Person : INotifyPropertyChanged
    {
        private bool isChecked;

        public bool IsChecked
        {
            get { return isChecked; }
            set 
            {
                isChecked = value;
                //OnPropertyChanged(nameof(IsChecked));
                OnPropertyChanged();
            }
        }
        private int id;
        public int Id { get => id; set { id = value; OnPropertyChanged(); } }

        private string name = null!;
        public string Name { get => name; set { name= value; OnPropertyChanged(); } }

        private int age;
        public int Age { get => age;set { age = value; OnPropertyChanged(); } }

        private int number;
        public int Number 
        { 
            get => number; 
            set 
            {
                number = value; OnPropertyChanged("Number"); 
                //OnPropertyChanged(nameof(Number));
                OnPropertyChanged();
            }
        }

        private Gerder gerder;
        public Gerder Gerder { get => gerder; set { gerder = value; OnPropertyChanged(); } }



        private string? description;

        public string? Description
        {
            get { return description; }
            set { description = value; OnPropertyChanged(); }
        }


        public event PropertyChangedEventHandler? PropertyChanged;
        //private void OnPropertyChanged(string propertyName)
        //{
        //    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        //}

        /// <summary>
        /// [CallerMemberName] 是一个特性，它允许你在没有显式传递属性名的情况下获取当前成员的名称。这使得代码更简洁，减少了错误的可能性。
        /// </summary>
        /// <param name="propertyName"></param>
        protected virtual void OnPropertyChanged([CallerMemberName]string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
